package com.tongtong.utils;

import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
import java.lang.annotation.*;
import java.util.List;

/**
 * @Title: ListNotEmpty
 * @Author zl
 * @Package com.oberyun.zhgc.common.utils
 * @Date 2025/6/20 15:46
 * @description: list判断是否为空
 */


@Documented
@Constraint(validatedBy = ListNotEmpty.ListNotEmptyValidator.class)
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ListNotEmpty {
    String message() default "List should not be empty";
    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};

    class ListNotEmptyValidator implements ConstraintValidator<ListNotEmpty, List<?>> {
        @Override
        public void initialize(ListNotEmpty constraintAnnotation) {
        }

        @Override
        public boolean isValid(List<?> value, ConstraintValidatorContext context) {
            return value != null && !value.isEmpty();
        }
    }
}
